<template>
  <el-dialog title="销售单产品选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal= false
    width="80%"
    center
    >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="销售单号" prop="saleNo">
        <el-input
          v-model="queryParams.saleNo"
          placeholder="请输入销售单号"
          clearable
          @keyup.enter.native="handleQuery"
          :value="msg2"
        />
      </el-form-item>

<!--      <el-form-item label="客户姓名" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->

<!--      <el-form-item label="下单时间">
        <el-date-picker
          v-model="daterangeSaleTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>-->
      <el-form-item>
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
<!--    </el-row>-->
    <el-table v-loading="loading" :data="listSaleOrderDetail" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column width="50" align="center" >
        <template v-slot="scope">
          <el-radio v-model="selectedClientId" :label="scope.row.id" @change="handleRowChange(scope.row)">{{""}}</el-radio>
        </template>
      </el-table-column>
<!--      <el-table-column label="下单时间" align="center" prop="saleTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.saleTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="销售单号" align="center" prop="saleNo" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="单价" align="center" prop="singlePrice" />
      <el-table-column label="销售数量" align="center" prop="saleCount" />
      <el-table-column label="是否定制" align="center" prop="customFlag" :formatter="customFlag"/>
      <el-table-column label="排产数量" align="center" prop="scheduleCount" />
      <el-table-column label="完工数量" align="center" prop="finishedCount" />
      <el-table-column label="已发货数量" align="center" prop="sentCount" />
      <el-table-column label="已退货数量" align="center" prop="refundCount" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listClient, getClient, delClient, addClient, updateClient } from "@/api/oa/md/client";
import { listSaleOrder, getSaleOrder, delSaleOrder, addSaleOrder, updateSaleOrder } from "@/api/oa/gw/saleOrder";
import { listSaleOrderDetail,getSaleOrderDetail,delSaleOrderDetail,addSaleOrderDetail,updateSaleOrderDetail } from "@/api/oa/gw/saleOrderDetail";

export default {
  name: "SalesDetailSelectSingle",
  dicts: ['mes_client_type','sys_yes_no'],
  props:['msg','msg2'],
  data() {
    return {
      showFlag:false,
      selectedClientId: undefined,
      selectedRow: undefined,
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户表格数据
      // clientList: [],
      // 销售单表格数据
      listSaleOrderDetail: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        saleNo:null,
        clientCode: null,
        clientName: null,
        clientNick: null,
        clientEn: null,
        clientDes: null,
        clientLogo: null,
        clientType: null,
        address: null,
        website: null,
        email: null,
        tel: null,
        contact1: null,
        contact1Tel: null,
        contact1Email: null,
        contact2: null,
        contact2Tel: null,
        contact2Email: null,
        creditCode: null,
        enableFlag: null,
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询销售单列表 */
    getList() {
      //alert(this.msg2);
      this.loading = true;
      this.queryParams.params = {};
      this.queryParams.saleNo = this.msg2;
/*      if (null != this.daterangeSaleTime && '' != this.daterangeSaleTime) {
        this.queryParams.params["beginSaleTime"] = this.daterangeSaleTime[0];
        this.queryParams.params["endSaleTime"] = this.daterangeSaleTime[1];
      }*/
      listSaleOrderDetail(this.queryParams).then(response => {
        this.listSaleOrderDetail = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询客户列表
    getList() {
      this.loading = true;
      listClient(this.queryParams).then(response => {
        this.clientList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },*/
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row){
        if(row){
            this.selectedRow = row;
        }
    },
    customFlag(row,index){
      if(row.customFlag == 1){
        return '是';
      }else {
        return '否';
      }
    },

    //行双击选中
    handleRowDbClick(row){
      if(row){
        this.selectedRow = row;
        this.$emit('onSelected',this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      debugger;
      if(row){
        this.selectedRow = row;
      }
    },
    //确定选中
    confirmSelect(){
        if(this.selectedClientId ==null || this.selectedClientId==0){
            this.$notify({
                title:'提示',
                type:'warning',
                message: '请至少选择一条数据!'
            });
            return;
        }
        this.$emit('onSelected',this.selectedRow);
        this.showFlag = false;
    }
  }
};
</script>
